<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	<link rel="stylesheet"
			href="${pageContext.request.contextPath}/css/base.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath}/css/info-reg.css" />
    <title>云云论坛-主贴</title>
    <script type="text/javascript"
			src="${pageContext.request.contextPath }/js/jquery.js"></script>
    <style type="text/css">
    .topicdiv{    	
      	 width:80%;
      	 margin: 0px auto;
      }
      td.{
      font-size: 10px;
      text-align: center;
      }
     body{
	 background-image: url(${pageContext.request.contextPath}/images/forum4.jpg);
	}
	
    </style>
  </head>
  <script type="text/javascript">
  	var oldColor;
	function choice(trObj) {
		oldColor = trObj.bgColor;
		trObj.bgColor = "yellow";
	}
	function leave(trObj) {
		trObj.bgColor = oldColor;
	}
  
  	function skipPage(currentPage) {
		var url = '${pageContext.request.contextPath }/ForumManager.action?method=queryTopicviewById&currPage='+currentPage;
		url+="&id="+document.getElementById("topic_Secid").value;
		window.location.href = url;
	}

	
	function removeTopic(tid,tuid){
	var currpage = ${requestScope.topicpage.currentPage};
	var deptName='${sessionScope.lwgKing.deptName}';
	var empWork='${sessionScope.lwgKing.empWork}';
	var uid='${sessionScope.lwgKing.userId}';
		if(deptName=="总经理办公室"){
				if(confirm("您确定要删除此贴？")){
				var url = '${pageContext.request.contextPath }/ForumManager.action?method=removeTopic&tid=' +tid+"&currPage="+currpage;
				url+="&id="+ document.getElementById("topic_Secid").value;
				window.location.href = url;
				}	
		}else if(empWork=="经理" && deptName=="财务部"){
				if(confirm("您确定要删除此贴？")){
				var url = '${pageContext.request.contextPath }/ForumManager.action?method=removeTopic&tid=' +tid+"&currPage="+currpage;
				url+="&id="+ document.getElementById("topic_Secid").value;
				window.location.href = url;
				}
		}else if(uid==tuid){
				if(confirm("您确定要删除此贴？")){
				var url = '${pageContext.request.contextPath }/ForumManager.action?method=removeTopic&tid=' +tid+"&currPage="+currpage;
				url+="&id="+ document.getElementById("topic_Secid").value;
				window.location.href = url;
				}
		}else{
		alert("亲您没有权限删除他人 主贴！请联系管理员！");
		}
	}
	
	function replyTopic(id,secId){
	var url = "${pageContext.request.contextPath }/ForumManager.action?method=queryById&id=" +id+"&secId="+secId;
	window.location.href = url;
	}
	
	function check(){
	var title=document.getElementById("title").value;
	var content=document.getElementById("contentid").value;
		if(title!=""&& content!=""){
			  $("#btnsave_id").attr("disabled",false);
	    }else{
	      $("#btnsave_id").attr("disabled",true);
	    }
		
	}
  </script>
  <body>
  <input type="hidden" id="userName_id" value="${login_User.userName }"/>
		<div class="title">
			<h2 align="center">
				主贴浏览
			</h2>
		</div>
		  <form action="${pageContext.request.contextPath }/ForumManager.action?method=saveTopic" method="post">
		<div class="main" align="center">
			<div style="height: 300px;">
				<table width="100%" align="center" cellspacing="0" cellpadding="0">
					<tr bgcolor="#e8c597">
						 <td width="15%">主题</td>
				       	  <td>内容</td>
				       	  <td width="15%">发帖时间</td>
				       	  <td width="15%">最后回复时间</td>
				       	  <td width="5%">回帖数</td>
				       	  <td >表情</td>
				       	  <td width="10%">发帖人</td>
						<td width="10%">
							&nbsp;操&nbsp;&nbsp;作
						</td>
					</tr>
					<c:forEach items="${requestScope.topicpage.data}" var="forum"
						varStatus="c">
						<tr 
							onmouseover=choice(this); onmouseout=leave(this);>
							<td>
							<input type="hidden" name="topicSecid" id="topic_Secid" value="${forum.topicSecid }"/>
								${forum.tTopic}
							</td>
							<td>
								${forum.tContents }
							</td>
							<td>
								${forum.tTime }
							</td>
							<td>
								${forum.lastReply }
							</td>
							<td>${forum.treplyCount }</td>
							<td> <img src="${pageContext.request.contextPath}/images/${forum.face}"></td>
							<td>
								${forum.userName }
							</td>

							<td >
								<div id="showId"  style="display: block;">
								<button style="cursor: pointer;color: navy;"
								type="button" onclick="replyTopic(${forum.topicId},${forum.topicSecid });">回帖</button>
								<button style="cursor: pointer;color: navy;"
								type="button" onclick="removeTopic(${forum.topicId},${forum.topicUserid });">删除</button>
								
								</div>
							</td>
						</tr>
						
					</c:forEach>
				</table>
			</div>
			<div align="center">
				<table width="100%" align="center" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<a onclick="skipPage('1');">首页</a>
						</td>
						<td>
							<a
								onclick="skipPage('${requestScope.topicpage.currentPage==1?1:requestScope.topicpage.currentPage-1 }');">上一页</a>
						</td>
						<td>
							<a
								onclick="skipPage('${requestScope.topicpage.currentPage==requestScope.topicpage.totalPage?(requestScope.topicpage.currentPage):(requestScope.topicpage.currentPage+1) }');">下一页</a>
						</td>
						<td>
							<a onclick="skipPage('${requestScope.topicpage.totalPage}');">末页</a>
						</td>
						<td>
							当前页码：${requestScope.topicpage.currentPage
							}/${requestScope.topicpage.totalPage}
						</td>
					</tr>
				</table>
			</div>
		</div>
		<hr/>
	<div class="title">
		<h3 align="center" style="color: green;">发帖内容：</h3>
	</div>	
  <div align="center">
    
        <input type="hidden" name="uid" value="${login_User.userId }"/>
      	<table align="center">
      		<tr>
      			<td>主题</td>
      			<td><input type="text" name="topic" size="60" id="title"  onmouseout="check();"/></td>
      		</tr>
      		<tr>
      			<td>表情</td>
      			<td>
      			  <img src="${pageContext.request.contextPath}/images/face0.gif">
      			  <input name="face" type="radio" value="face0.gif" checked="checked"/>
      			  <img src="${pageContext.request.contextPath}/images/face1.gif">
      			  <input name="face" type="radio" value="face1.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face2.gif">
      			  <input name="face" type="radio" value="face2.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face3.gif">
      			  <input name="face" type="radio" value="face3.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face4.gif">
      			  <input name="face" type="radio" value="face4.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face5.gif">
      			  <input name="face" type="radio" value="face5.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face6.gif">
      			  <input name="face" type="radio" value="face6.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face7.gif">
      			  <input name="face" type="radio" value="face7.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face8.gif">
      			  <input name="face" type="radio" value="face8.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face9.gif">
      			  <input name="face" type="radio" value="face9.gif" />
      			  <img src="${pageContext.request.contextPath}/images/face10.gif">
      			  <input name="face" type="radio" value="face10.gif" />
      			  
      			</td>
      		</tr>
      		<tr>
      			<td>内容</td>
      			<td><textarea cols="50" rows="2" name="content" id="contentid" onmouseout="check();"></textarea></td>
      		</tr>
      		<tr>
      			<td colspan="2" align="center">
      			  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      			   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      			  <input type="submit" value="提交" disabled id="btnsave_id"/>
      			  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      			  <input type="reset" value="重置"/>
      			</td>
      		</tr>
      	</table>
    </div>
      </form>
   
  </body>
</html>
